home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / linuxcon.000 / linuxcon / linuxconf-1.6 / dialog / dialog.h < prev    next >
C/C++ Source or Header  |  1996-07-19  |  10KB  |  433 lines

  1. #pragma interface
  2. #ifndef DIALOG_H
  3. #define DIALOG_H
  4.  
  5. /* Optionnal buttons for menubox */
  6. #define MENUBUT_SAVE    1
  7. #define MENUBUT_ADD        2
  8. #define MENUBUT_DEL        4
  9. #define MENUBUT_INS        8
  10. // Other button setup internally
  11. #define MENUBUT_OK        16
  12. #define MENUBUT_ACCEPT        32
  13. #define MENUBUT_CANCEL        64
  14. #define MENUBUT_QUIT        128
  15. #define MENUBUT_YES        256
  16. #define MENUBUT_NO        512
  17. #define MENUBUT_EDIT        1024
  18. #define MENUBUT_RESET        2048
  19.  
  20. enum DIALOG_MODE{
  21.     DIALOG_CURSES,    // Use Ncurse
  22.     DIALOG_HTML,    // Web mode
  23.     DIALOG_GUI,        // One day maybe
  24. };
  25.     
  26. extern DIALOG_MODE dialog_mode;
  27.  
  28. // Return code of many function
  29. enum MENU_STATUS {
  30.     MENU_NULL,
  31.     MENU_ESCAPE,
  32.     MENU_CANCEL,
  33.     MENU_QUIT,
  34.     MENU_SAVE,
  35.     MENU_OK,
  36.     MENU_ACCEPT,
  37.     MENU_DEL,
  38.     MENU_INS,
  39.     MENU_ADD,
  40.     MENU_YES,
  41.     MENU_NO,
  42.     MENU_EDIT,
  43.     MENU_RESET,
  44.     MENU_INTERNAL_TIMEOUT,        // Used to signal a one second delay
  45.                                 // to the dialog editor
  46.     MENU_HELP,                // Help button, used internally
  47. };
  48.  
  49.  
  50. #define MAX_LEN        2048
  51.  
  52. #include <ncurses/curses.h>
  53.  
  54. #ifndef MISC_H
  55.     #include "../misc/misc.h"
  56. #endif
  57.     
  58. class BUTTONS_INFO;
  59. class SSTRINGS;
  60. class HELP_FILE;
  61.  
  62. class FIELD_MSG{
  63. public:
  64.     char is_loaded;        // Is there a message to process
  65.     void *key;            // Generally a pointer to a common
  66.                         // data used by field to talk to each other
  67.     int  int_val;        // Value of the message
  68.                         // It is expected to see other type
  69.                         // to communicate more complex messages
  70.                         // between fields.
  71.     /*~PROTOBEG~ FIELD_MSG */
  72. public:
  73.     FIELD_MSG (void);
  74.     /*~PROTOEND~ FIELD_MSG */
  75. };
  76.  
  77. class FIELD: public ARRAY_OBJ{
  78. protected:
  79.     char readonly;        // This field can't be modified
  80.     friend class DIALOG;
  81. protected:
  82.     char *prompt;
  83. public:
  84.     struct {
  85.         int x;    // Horizontal position of the input boxes
  86.         int width;
  87.         int y;    // Vertical coordinate of the input boxes
  88.     } box;
  89. public:                 
  90.     virtual void drawtxt(WINDOW *)=0;
  91.     virtual void dokey(WINDOW *, int key, FIELD_MSG &msg)=0;
  92.     virtual void save()=0;
  93.     virtual void restore()=0;
  94.     virtual void html_draw(int nofield)=0;
  95.     virtual int html_validate(int nofield)=0;
  96.     /*~PROTOBEG~ FIELD */
  97. public:
  98.     FIELD (const char *_prompt);
  99.     void draw (WINDOW *dialog);
  100.     virtual void format_htmlkey (char *key, int nof);
  101.     virtual const char *getmenustr (void);
  102. protected:
  103.     virtual int getwidth1 (void);
  104. public:
  105.     int is_readonly (void);
  106. protected:
  107.     virtual void processmsg (WINDOW *, FIELD_MSG&, int);
  108. public:
  109.     void set_readonly (void);
  110.     virtual void setcursor (WINDOW *dialog);
  111. protected:
  112.     virtual void setwidth1 (int);
  113. public:
  114.     virtual void unselect (WINDOW *);
  115.     virtual ~FIELD (void);
  116.     /*~PROTOEND~ FIELD */
  117. };
  118.  
  119. class FIELD_STRING_BASE: public FIELD{
  120. protected:
  121.     struct {
  122.         int input;    // Current position in window */
  123.         int scroll;    // Amount of horizontal scrolling so far */
  124.     }x;
  125.     int size;
  126.     char *buf;        // For editing
  127. protected:
  128.     int password_mode;    // Echo on or not
  129.     /*~PROTOBEG~ FIELD_STRING_BASE */
  130. protected:
  131.     FIELD_STRING_BASE (const char *_prompt,
  132.          const char *_str,
  133.          int maxsiz);
  134.     FIELD_STRING_BASE (const char *_prompt,
  135.          int maxsiz);
  136. public:
  137.     void dokey (WINDOW *dialog,
  138.          int key,
  139.          FIELD_MSG&);
  140.     void drawtxt (WINDOW *dialog);
  141.     void html_draw (int nof);
  142.     int html_validate (int nof);
  143. private:
  144.     void init (int maxsiz);
  145. public:
  146.     void setcursor (WINDOW *dialog);
  147.     ~FIELD_STRING_BASE (void);
  148.     /*~PROTOEND~ FIELD_STRING_BASE */
  149. };
  150.  
  151. class FIELD_STRING: public FIELD_STRING_BASE{
  152. protected:
  153.     char *str;        // String to edit
  154.     char *backup;
  155.     /*~PROTOBEG~ FIELD_STRING */
  156. public:
  157.     FIELD_STRING (const char *_prompt,
  158.          char *_str,
  159.          int maxsiz);
  160.     void restore (void);
  161.     void save (void);
  162.     ~FIELD_STRING (void);
  163.     /*~PROTOEND~ FIELD_STRING */
  164. };
  165.  
  166. class SSTRING;
  167. class FIELD_SSTRING: public FIELD_STRING_BASE{
  168. protected:
  169.     SSTRING &str;
  170.     SSTRING backup;
  171.     /*~PROTOBEG~ FIELD_SSTRING */
  172. public:
  173.     FIELD_SSTRING (const char *_prompt,
  174.          SSTRING&_str);
  175.     void html_draw (int nof);
  176.     void restore (void);
  177.     void save (void);
  178.     /*~PROTOEND~ FIELD_SSTRING */
  179. };
  180.  
  181. class FIELD_PASSWORD: public FIELD_SSTRING{
  182.     /*~PROTOBEG~ FIELD_PASSWORD */
  183. public:
  184.     FIELD_PASSWORD (const char *_prompt,
  185.          SSTRING&_str);
  186.     /*~PROTOEND~ FIELD_PASSWORD */
  187. };
  188.  
  189.  
  190. // FIELD_STRING with a helper hot key
  191. // generally used to setup combo-box
  192. class FIELD_STRING_HELP: public FIELD_SSTRING{
  193. protected:
  194.     virtual void assist(WINDOW *dialog)=0;
  195.     /*~PROTOBEG~ FIELD_STRING_HELP */
  196. public:
  197.     FIELD_STRING_HELP (const char *_prompt,
  198.          SSTRING&_str);
  199.     void dokey (WINDOW *dialog,
  200.          int key,
  201.          FIELD_MSG&msg);
  202.     void drawtxt (WINDOW *dialog);
  203.     /*~PROTOEND~ FIELD_STRING_HELP */
  204. };
  205.  
  206. class LIST_STR;
  207. class FIELD_COMBO: public FIELD_STRING_HELP{
  208. protected:
  209.     LIST_STR *opts;
  210.     /*~PROTOBEG~ FIELD_COMBO */
  211. public:
  212.     FIELD_COMBO (const char *_prompt, SSTRING&_str);
  213.     void addopt (const char *str);
  214.     void addopt (const char *value,
  215.          const char *verbose);
  216. protected:
  217.     void assist (WINDOW *dialog);
  218. public:
  219.     ~FIELD_COMBO (void);
  220.     /*~PROTOEND~ FIELD_COMBO */
  221. };
  222.  
  223. class FIELD_COMBO_MANY: public FIELD_COMBO{
  224.     /*~PROTOBEG~ FIELD_COMBO_MANY */
  225. public:
  226.     FIELD_COMBO_MANY (const char *_prompt,
  227.          SSTRING&_str);
  228.     void addopt (const char *str, char &selected);
  229. protected:
  230.     void assist (WINDOW *dialog);
  231. public:
  232.     /*~PROTOEND~ FIELD_COMBO_MANY */
  233. };
  234.  
  235. class FIELD_CHECK_RADIO: public FIELD{
  236. protected:
  237.     char *title;
  238.     char *var;
  239.     char val;
  240.     char backup;
  241.     /*~PROTOBEG~ FIELD_CHECK_RADIO */
  242. public:
  243.     FIELD_CHECK_RADIO (const char *_prompt,
  244.          char &_var,
  245.          const char *_title);
  246.     void drawtxt_check (WINDOW *dialog,
  247.          char openchar,
  248.          char closechar,
  249.          char selchar);
  250.     void format_htmlkey (char *key, int nof);
  251.     void restore (void);
  252.     void save (void);
  253.     void setcursor (WINDOW *dialog);
  254.     ~FIELD_CHECK_RADIO (void);
  255.     /*~PROTOEND~ FIELD_CHECK_RADIO */
  256. };
  257.  
  258.  
  259. class FIELD_CHECK: public FIELD_CHECK_RADIO{
  260.     /*~PROTOBEG~ FIELD_CHECK */
  261. public:
  262.     FIELD_CHECK (const char *_prompt,
  263.          char &_var,
  264.          const char *_title);
  265.     void dokey (WINDOW *dialog, int key, FIELD_MSG&);
  266.     void drawtxt (WINDOW *dialog);
  267.     void html_draw (int nof);
  268.     int html_validate (int nof);
  269.     /*~PROTOEND~ FIELD_CHECK */
  270. };
  271. class FIELD_RADIO: public FIELD_CHECK_RADIO{
  272.     char instance_val;
  273.     FIELD_RADIO *next;        // All field radio are in a linked list
  274.                             // see radio.c
  275.     /*~PROTOBEG~ FIELD_RADIO */
  276. public:
  277.     FIELD_RADIO (const char *_prompt,
  278.          char &_var,
  279.          char _instance_val,
  280.          const char *_title);
  281.     void dokey (WINDOW *, int key, FIELD_MSG&msg);
  282.     void drawtxt (WINDOW *dialog);
  283.     void html_draw (int);
  284.     int html_validate (int);
  285. private:
  286.     FIELD_RADIO *locate_key (char *key);
  287. protected:
  288.     void processmsg (WINDOW *dialog,
  289.          FIELD_MSG&msg,
  290.          int drawok);
  291. public:
  292.     ~FIELD_RADIO (void);
  293.     /*~PROTOEND~ FIELD_RADIO */
  294. };
  295.  
  296. class BUTTONS_INFO;
  297.  
  298. class DIALOG: public ARRAY{
  299. protected:
  300.     BUTTONS_INFO *buttons;
  301.     int button;    // Button currently selected or -1
  302.     int width;
  303.     int height;
  304.     SSTRING title;
  305.     SSTRING intro;
  306.     SSTRING icon;
  307.     int offset;    // Number of the first visible field
  308.     int nbvisible;    // How many field are visible (window height)
  309.     struct {
  310.         SSTRING save;
  311.         SSTRING ins;
  312.         SSTRING add;
  313.         SSTRING del;
  314.     }what;    // Small explanation about the behavior of some special
  315.         // buttons.
  316.     /*~PROTOBEG~ DIALOG */
  317. public:
  318.     DIALOG (void);
  319.     void addwhat (const char *help);
  320.     void delwhat (const char *help);
  321. private:
  322.     void draw (WINDOW *dialog);
  323.     void drawarrow_if (WINDOW *win,
  324.          bool condition,
  325.          bool&flag,
  326.          bool top,
  327.          chtype carac);
  328. protected:
  329.     void drawf (WINDOW *dialog);
  330. public:
  331.     MENU_STATUS edit (const char *_title,
  332.          const char *_intro,
  333.          HELP_FILE&helpfile,
  334.          int &nof,
  335.          int but_options);
  336.     MENU_STATUS edit (const char *_title,
  337.          const char *_intro,
  338.          const char *helpfile,
  339.          int &nof,
  340.          int but_options);
  341.     MENU_STATUS edit (const char *_title,
  342.          const char *intro,
  343.          HELP_FILE&helpfile,
  344.          int nof);
  345.     MENU_STATUS edit (const char *_title,
  346.          const char *intro,
  347.          const char *helpfile,
  348.          int nof);
  349. private:
  350.     MENU_STATUS edithtml (int &nof);
  351. public:
  352.     MENU_STATUS editmenu (const char *title,
  353.          const char *prompt,
  354.          HELP_FILE&helpfile,
  355.          int &sel,
  356.          int options);
  357.     MENU_STATUS editmenu (const char *title,
  358.          const char *prompt,
  359.          const char *helpfile,
  360.          int &sel,
  361.          int options);
  362. private:
  363.     MENU_STATUS editterm (int &nof, int but_options);
  364.     void fixwidth1 (void);
  365. public:
  366.     FIELD *getitem (int no);
  367.     const char *getmenustr (int choice);
  368. private:
  369.     void html_draw (DIALOG *spc);
  370.     void html_draw (void);
  371.     void html_draw_end (void);
  372.     void html_draw_fields (void);
  373.     void html_draw_form (void);
  374.     void html_draw_intro (void);
  375.     void html_draw_top (void);
  376.     int html_validate (void);
  377. public:
  378.     void inswhat (const char *help);
  379. protected:
  380.     virtual int keymove (WINDOW *dialog,
  381.          int key,
  382.          int &nof);
  383. public:
  384.     void new_menuitem (const SSTRING&prompt1,
  385.          const SSTRING&prompt2);
  386.     void new_menuitem (const char *prompt1,
  387.          const SSTRING&prompt2);
  388.     void new_menuitem (const char *prompt1,
  389.          const char *prompt2);
  390.     FIELD_CHECK *newf_chk (const char *prompt,
  391.          char &var,
  392.          const char *title);
  393.     FIELD_COMBO *newf_combo (const char *prompt,
  394.          SSTRING&str);
  395.     FIELD_COMBO_MANY *newf_combo_many (const char *prompt,
  396.          SSTRING&str);
  397.     FIELD *newf_num (const char *prompt, int &val);
  398.     FIELD_PASSWORD *newf_pass (const char *prompt,
  399.          SSTRING&str);
  400.     FIELD_RADIO *newf_radio (const char *prompt,
  401.          char &var,
  402.          char instance_val,
  403.          const char *title);
  404.     FIELD_SSTRING *newf_str (const char *prompt,
  405.          SSTRING&str);
  406.     FIELD_STRING *newf_str (const char *prompt,
  407.          char *str,
  408.          int maxsiz);
  409.     void newf_title (const char *prompt, const char *msg);
  410. private:
  411.     void processmsg (WINDOW *dialog, FIELD_MSG&msg);
  412. public:
  413.     void restore (void);
  414.     void save (void);
  415.     void savewhat (const char *help);
  416.     void seticon (const char *_icon);
  417. private:
  418.     void setoffset (int newoff);
  419.     void setup (void);
  420.     void showtimeout (WINDOW *win);
  421. public:
  422.     int was_modified (void);
  423.     ~DIALOG (void);
  424.     /*~PROTOEND~ DIALOG */
  425. };
  426.  
  427.  
  428. class HTML_VARVAL;
  429.  
  430. #include "dialog.p"
  431.  
  432. #endif
  433.